package com.oocl.euc.core.maintenance.service;

import com.oocl.euc.core.maintenance.model.EmailTemplate;
import com.oocl.euc.core.maintenance.repository.EmailTemplateRepository;
import com.oocl.euc.core.requestform.repository.SubCategoryRepository;
import com.oocl.euc.framework.base.persistence.IBaseRepository;
import com.oocl.euc.framework.base.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class EmailTemplateService extends BaseService<EmailTemplate, Long> {

    @Autowired
    EmailTemplateRepository emailTemplateRepository;
    @Autowired
    SubCategoryRepository subCategoryRepository;

    @Override
    protected IBaseRepository<EmailTemplate, Long> getRepository() {
        return emailTemplateRepository;
    }

    public EmailTemplate findByEmailTempalteKey(String emailTemplateKey){
        return emailTemplateRepository.findByEmailTempalteKey(emailTemplateKey);
    }

public void update(EmailTemplate emailTemplate) {
        EmailTemplate newEmailTemplate = this.findOne(emailTemplate.getId());
        newEmailTemplate.setSubject(emailTemplate.getSubject());
        newEmailTemplate.setEmailCC(emailTemplate.getEmailCC());
        newEmailTemplate.setDescription(emailTemplate.getDescription());
        newEmailTemplate.setSendTo(emailTemplate.getSendTo());
        newEmailTemplate.setContent(emailTemplate.getContent());
        newEmailTemplate.setEmailBCC(emailTemplate.getEmailBCC());
        newEmailTemplate.setSendFrom(emailTemplate.getSendFrom());
        this.save(newEmailTemplate);
    }
}
